home *** CD-ROM | disk | FTP | other *** search
/ CD World Haziran 1997 / CD World Haziran 1997.iso / Programlama ve Gelistirme / DTime / _SETUP.1 / Datetest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-04  |  43.2 KB  |  1,464 lines

  1. #include "stdafx.h"         // MFC core and standard components
  2. #include "dtime.h"          // DTime main include
  3.  
  4.  
  5.  
  6. //the test app        
  7. class CApp : public CWinApp
  8. {
  9.   virtual BOOL InitInstance(); 
  10. };
  11.  
  12. //create the app
  13. CApp NEAR theApp;
  14.  
  15.  
  16. //test code goes in InitInstance under Windows
  17. BOOL CApp::InitInstance()
  18. {              
  19.   DWORD StartTicks = GetTickCount();
  20.  
  21.   //Initialise DTime
  22.   InitDTime();
  23.                     
  24.   //Set the title of the console Window
  25.   SetConsoleTitle(_T("Test program to exercise the DTime package"));
  26.  
  27.   //Display some intro text
  28.   _tprintf(_T("This program is best used under a debugger so\n"));
  29.   _tprintf(_T("that code can be stepped into etc.\n"));
  30.   _tprintf(_T("Some calls to Dtime contained in this code is designed to cause ASSERTIONS\n"));
  31.   _tprintf(_T("<Hit Enter to continue>\n"));
  32.   int chr = getchar();
  33.  
  34.   //first some helpful information will be displayed
  35.   _tprintf(_T("\nTimezone Standard Name is currently \"%s\"\n"), CLDate::StandardName());
  36.   _tprintf(_T("Timezone Bias is currently %s\n"), (CLDate::TimezoneBias()).Format());
  37.   _tprintf(_T("Daylight Name is currently \"%s\"\n"), CLDate::DaylightName());
  38.   _tprintf(_T("Daylight Bias is currently %s\n"), (CLDate::DaylightBias()).Format());
  39.  
  40.  
  41.   //Test of the CDate class
  42.  
  43.   CDate xstr(1996, CDate::JANUARY, 1);
  44.   CString sString = xstr.Format();
  45.  
  46.  
  47.   //first all the constructors
  48.   CDate x(1582, CDate::OCTOBER, 15);    //GDN = 0
  49.   x = CDate(1992, CDate::OCTOBER, 10);  //GDN = 149745
  50.   x = CDate(-4712, CDate::JANUARY, 1);  //GDN = -2299161
  51.   x = CDate(1582, CDate::OCTOBER, 4);   //GDN = -1;
  52.  
  53.  
  54.  
  55.   //should be invalid dates, causing ASSERTs
  56.   /*
  57.   x = CDate(1582, CDate::OCTOBER, 8);
  58.   ASSERT(!x.IsValid());
  59.   x = CDate(1995, CDate::FEBRUARY, 29);
  60.   ASSERT(!x.IsValid());
  61.   x = CDate(1900, CDate::FEBRUARY, 29);
  62.   ASSERT(!x.IsValid());
  63.   x = CDate(1582, CDate::JANUARY, 32);
  64.   ASSERT(!x.IsValid());
  65.   x = CDate(1900, 13, 8);
  66.   ASSERT(!x.IsValid());
  67.   x = CDate(5879612L, 1, 1);
  68.   ASSERT(!x.IsValid());
  69.   x = CDate(5879611L, 8, 1);
  70.   ASSERT(!x.IsValid());
  71.   x = CDate(5879612L, 7, 12);
  72.   ASSERT(!x.IsValid());
  73.   */
  74.  
  75.  
  76.   //should be invalid dates and should ASSERT
  77.   /*
  78.   CDate::SetDoAsserts(TRUE);
  79.   x = CDate(1582, CDate::OCTOBER, 8);
  80.   x = CDate(1995, CDate::FEBRUARY, 29);
  81.   x = CDate(1900, CDate::FEBRUARY, 29);
  82.   x = CDate(1582, CDate::JANUARY, 32);
  83.   x = CDate(1900, 13, 8);
  84.   x = CDate(5879612L, 1, 1);
  85.   x = CDate(5879611L, 8, 1);
  86.   x = CDate(5879612L, 7, 12);
  87.   */
  88.  
  89.  
  90.   //construction using DateS structure
  91.   DateS ds;
  92.   ds.lYear = 1582;
  93.   ds.wMonth = CDate::OCTOBER;
  94.   ds.wDay = 15;
  95.   x = CDate(ds.lYear, ds.wMonth, ds.wDay);  //GDN = 0
  96.  
  97.  
  98.   //Construction using the Win32 SYSTEMTIME structure
  99.   SYSTEMTIME st;
  100.   st.wYear = 1582;
  101.   st.wMonth = 10;
  102.   st.wDay = 15;
  103.   x = CDate(st);
  104.  
  105.  
  106.   //Construction using the direct count of days
  107.   x = CDate(0, CDate::EPOCH_JD);    //GDN = -2299161
  108.   x = CDate(0, CDate::EPOCH_GREG);  //GDN = 0
  109.   x = CDate(0, CDate::EPOCH_MJD);   //GDN = 100839
  110.   x = CDate(0, CDate::EPOCH_1900);  //GDN = 115860
  111.   x = CDate(0, CDate::EPOCH_1950);  //GDN = 134122
  112.   x = CDate(0, CDate::EPOCH_CTIME); //GDN = 141427
  113.   x = CDate(0, CDate::EPOCH_2000);  //GDN = 152384
  114.   
  115.  
  116.  
  117.   //CTime Construction
  118.   CTime z(1970, 1, 2, 0, 0, 0);
  119.   x = CDate(z);  //GDN = 141428
  120.   CString s = x.Format();
  121.       
  122.   //COleDateTime Construction
  123.   COleDateTime dt(1992, CDate::OCTOBER, 10, 0, 0, 0);
  124.   x = CDate(dt);  //GDN = 149745
  125.   s = x.Format();
  126.   dt = COleDateTime(1970, 1, 2, 0, 0, 0);
  127.   x = CDate(dt);  //GDN = 141428
  128.   s = x.Format();
  129.  
  130.  
  131.   //Static Constructors
  132.   x = CDate::CurrentDate();
  133.   s = x.Format();
  134.   _tprintf(_T("The current date is %s\n"), s);
  135.   x = CDate::FirstCurrentMonth();
  136.   s = x.Format();
  137.   _tprintf(_T("The first of the current month is %s\n"), s);
  138.   x = CDate::FirstCurrentYear();
  139.   s = x.Format();
  140.   _tprintf(_T("The First of the current year is %s\n"), s);
  141.   x = CDate::LastCurrentYear();
  142.   s = x.Format();
  143.   _tprintf(_T("The last of the current year is %s\n"), s);
  144.   x = CDate::JDEpoch();
  145.   s = x.Format();
  146.   _tprintf(_T("The Julian Day Epoch is %s\n"), s);
  147.   x = CDate::MJDEpoch();
  148.   s = x.Format();
  149.   _tprintf(_T("The Modified Julian Day Epoch is %s\n"), s);
  150.   x = CDate::Epoch1900();
  151.   s = x.Format();
  152.   _tprintf(_T("The 1900 Epoch is %s\n"), s);
  153.   x = CDate::Epoch1950();
  154.   s = x.Format();
  155.   _tprintf(_T("The 1950 Epoch is %s\n"), s);
  156.   x = CDate::EpochCTime();
  157.   s = x.Format();
  158.   _tprintf(_T("The CTime Epoch is %s\n"), s);
  159.   x = CDate::Epoch2000();
  160.   s = x.Format();
  161.   _tprintf(_T("The 2000 Epoch is %s\n"), s);
  162.   x = CDate::GregorianEpoch();
  163.   s = x.Format();
  164.   _tprintf(_T("The Gregorian Epoch is %s\n"), s);
  165.  
  166.  
  167.   //Try the static operations
  168.  
  169.   ASSERT(CDate::IsLeap(2000));
  170.   ASSERT(!CDate::IsLeap(1900));
  171.   ASSERT(!CDate::IsLeap(1902));
  172.   ASSERT(CDate::IsLeap(1400));
  173.   ASSERT(CDate::IsLeap(1300));
  174.   ASSERT(!CDate::IsLeap(1302));
  175.   ASSERT(CDate::DaysInYear(2000) == 366);
  176.   ASSERT(CDate::DaysInYear(1998) == 365);
  177.   ASSERT(CDate::DaysInMonth(CDate::JANUARY, TRUE) == 31);
  178.   ASSERT(CDate::DaysInMonth(CDate::FEBRUARY, TRUE) == 29);
  179.   ASSERT(CDate::DaysInMonth(CDate::FEBRUARY, FALSE) == 28);
  180.   ASSERT(CDate::DaysInMonth(CDate::JUNE, TRUE) == 30);
  181.   ASSERT(CDate::DaysSinceJan0(CDate::JANUARY, 1, TRUE) == 1);
  182.   ASSERT(CDate::DaysSinceJan0(CDate::JANUARY, 1, FALSE) == 1);
  183.   ASSERT(CDate::DaysSinceJan0(CDate::DECEMBER, 31, TRUE) == 366);
  184.   ASSERT(CDate::DaysSinceJan0(CDate::DECEMBER, 31, FALSE) == 365);
  185.   ASSERT(CDate::DaysSinceJan0(CDate::JULY, 13, TRUE) == 195);
  186.   ASSERT(CDate::DaysSinceJan0(CDate::JULY, 13, FALSE) == 194);
  187.   ASSERT(CDate::DaysSinceJan1(CDate::DECEMBER, 31, TRUE) == 365);
  188.   ASSERT(CDate::DaysSinceJan1(CDate::DECEMBER, 31, FALSE) == 364);
  189.   ASSERT(CDate::DaysSinceJan1(CDate::JULY, 13, TRUE) == 194);
  190.   ASSERT(CDate::DaysSinceJan1(CDate::JULY, 13, FALSE) == 193);
  191.   ASSERT(CDate::DaysSinceJan1(CDate::JANUARY, 1, TRUE) == 0);
  192.   ASSERT(CDate::DaysSinceJan1(CDate::JANUARY, 1, FALSE) == 0);
  193.   
  194.   WORD m = CDate::CurrentMonth();
  195.   _tprintf(_T("The current month is %d\n"), m);
  196.  
  197.   WORD d = CDate::CurrentDay();
  198.   _tprintf(_T("The current day is %d\n"), d);
  199.  
  200.   long y = CDate::CurrentYear();
  201.   _tprintf(_T("The current year is %ld\n"), y);
  202.  
  203.   WORD dow = CDate::CurrentDayOfWeek();
  204.   _tprintf(_T("The current day of week is %d\n"), dow);
  205.  
  206.  
  207.   //is it possible to have only 3 of a weekday in a month
  208.   //Construction using the WeekOfMonth parameter
  209.   x = CDate(1995, 9, 3, CDate::FRIDAY);
  210.   ASSERT(x == CDate(1995, 9, 15));
  211.   x = CDate(1995, 9, 1, CDate::SATURDAY);
  212.   ASSERT(x == CDate(1995, 9, 2));
  213.   x = CDate(1995, 9, 1, CDate::TUESDAY);
  214.   ASSERT(x == CDate(1995, 9, 5));
  215.   x = CDate(1995, 9, 5, CDate::SUNDAY);
  216.   ASSERT(x == CDate(1995, 9, 24));
  217.   x = CDate(1995, 9, 5, CDate::FRIDAY);
  218.   ASSERT(x == CDate(1995, 9, 29));
  219.  
  220.  
  221.  
  222.  
  223.   //Testing static holiday constructors
  224.  
  225.   //some of these will need at least 2 day tests
  226.  
  227.   x = CDate::NewYearsDay();
  228.   s = x.Format();
  229.   _tprintf(_T("New Years Day occurs on %s this year\n"), s);
  230.  
  231.   x = CDate::ValentinesDay();
  232.   s = x.Format();
  233.   _tprintf(_T("Valentines Day occurs on %s this year\n"), s);
  234.  
  235.   x = CDate::StPatricksDay();
  236.   s = x.Format();
  237.   _tprintf(_T("St Patricks Day occurs on %s this year\n"), s);
  238.  
  239.   x = CDate::AshWednesday();
  240.   s = x.Format();
  241.   _tprintf(_T("Ash Wednesday occurs on %s this year\n"), s);
  242.  
  243.   x = CDate::GoodFriday();
  244.   s = x.Format();
  245.   _tprintf(_T("Good Friday occurs on %s this year\n"), s);
  246.  
  247.   x = CDate::EasterSunday();
  248.   s = x.Format();
  249.   _tprintf(_T("Easter Sunday occurs on %s this year\n"), s);
  250.  
  251.   x = CDate::CanadaDay();
  252.   s = x.Format();
  253.   _tprintf(_T("Canada Day occurs on %s this year\n"), s);
  254.  
  255.   x = CDate::IndependenceDay();
  256.   s = x.Format();
  257.   _tprintf(_T("American Independence Day occurs on %s this year\n"), s);
  258.  
  259.   x = CDate::BastilleDay();
  260.   s = x.Format();
  261.   _tprintf(_T("Bastille Day occurs on %s this year\n"), s);
  262.  
  263.   x = CDate::ChristmasDay();
  264.   s = x.Format();
  265.   _tprintf(_T("Christmas Day occurs on %s this year\n"), s);
  266.  
  267.   
  268.   //test the range of the class
  269.  
  270.   long StartYear = -50000;
  271.   long EndYear = 50000;
  272.  
  273.   //Uncomment if you want to perform a full range check on CDate's construction routines
  274.   /*
  275.   _tprintf(_T("\n\nNow going to construct a CDate for all dates\n"));
  276.   _tprintf(_T("between the years %ld and %ld\n"), StartYear, EndYear);
  277.   _tprintf(_T("This may take a while\n"));
  278.   _tprintf(_T("<Hit Enter to continue>\n"));
  279.   chr = getchar();
  280.   DWORD StartTime = GetTickCount();
  281.  
  282.   for (long lYear = StartYear; lYear < EndYear; lYear++)
  283.   {
  284.     if (lYear % 100 == 0)
  285.        _tprintf(_T("Testing Year %ld\n"), lYear);
  286.     for (WORD wMonth = CDate::JANUARY; wMonth <= CDate::DECEMBER; wMonth++)
  287.     {
  288.       for (WORD wDay = 1; wDay <= CDate::DaysInMonth(wMonth, CDate::IsLeap(lYear)); wDay++)
  289.       {
  290.         x = CDate(lYear, wMonth, wDay);
  291.         if (x.IsValid())
  292.         {
  293.           DateS ds = x.GetDate();
  294.           if ((ds.lYear != lYear) || (ds.wMonth != wMonth) || (ds.wDay != wDay))
  295.           {
  296.             s = x.Format();
  297.             _tprintf(_T("Error occured testing %s\n"), s);
  298.           }
  299.         }
  300.       }
  301.     }
  302.   }
  303.  
  304.   DWORD EndTime = GetTickCount();
  305.   DWORD SecondsTaken = (EndTime - StartTime)/1000;
  306.   _tprintf(_T("The time taken for the validity test was %ld seconds\n"), SecondsTaken);
  307.   _tprintf(_T("Or about %ld seconds for 1000 years\n"), (SecondsTaken*1000)/(EndYear - StartYear));
  308.   _tprintf(_T("<Hit Enter to continue>\n"));
  309.   chr = getchar();
  310.   */
  311.   
  312.  
  313.  
  314.  
  315.   //change the time when the gregorian Calendar comes into action
  316.  
  317.   //for the moment , the values will be changed to match some known values
  318.   /*
  319.   x = CDate(50000, 1, 30);
  320.   s = x.Format();
  321.   _tprintf(_T("%s (NS) Gregorian Day Number is ", s);
  322.   _tprintf(_T("%ld\n"), x.JD());
  323.   CDate::SetEndJulianCalendar(x.GetYear()+1, 8, 10);
  324.   CDate::SetBeginGregCalendar(x.GetYear()+1, 8, 20);
  325.   x = CDate(50000, 1, 30);
  326.   s = x.Format();
  327.   _tprintf(_T("%s (OS) Gregorian Day Number is ", s);
  328.   _tprintf(_T("%ld\n"), x.JD());
  329.   */
  330.  
  331.  
  332.   //try out the accessors for the end of Julian and
  333.   //begin of Gregorian dates
  334.   LONG Year;
  335.   WORD Month;
  336.   WORD Day;
  337.   CDate::GetEndJulianCalendar(Year, Month, Day);
  338.   CDate EndJulian(Year, Month, Day);
  339.   s = EndJulian.Format();
  340.   _tprintf(_T("The End of the Julian calendar occurs on %s\n"), s);
  341.   CDate::GetBeginGregorianCalendar(Year, Month, Day);
  342.   CDate BeginGreg(Year, Month, Day);
  343.   s = BeginGreg.Format();
  344.   _tprintf(_T("The begining of the Gregorian calendar occurs on %s\n"), s);
  345.   
  346.     
  347.   // Try out the other operators
  348.   long l = 0;
  349.   x = CDate::CurrentDate();
  350.   l = x.Since1900Epoch();
  351.   _tprintf(_T("Today is %ld days since the 1900 epoch\n"), l);
  352.   l = x.Since1950Epoch();
  353.   _tprintf(_T("Today is %ld days since the 1950 epoch\n"), l);
  354.   l = x.SinceCTimeEpoch();
  355.   _tprintf(_T("Today is %ld days since the CTime epoch\n"), l);
  356.   l = x.Since2000Epoch();
  357.   _tprintf(_T("Today is %ld days since the 2000 epoch\n"), l);
  358.   l = x.GDN();
  359.   _tprintf(_T("Today is %ld days since the Gregorian epoch\n"), l);
  360.   l = x.JD();
  361.   _tprintf(_T("Today is %ld days since the Julian Day epoch\n"), l);
  362.   if (x.IsLeap())
  363.     _tprintf(_T("This year is a leap year\n"));
  364.   else
  365.     _tprintf(_T("This year is not a leap year\n"));
  366.   WORD diy = x.DaysInYear();
  367.   _tprintf(_T("This year contains %d days \n"), diy);
  368.   WORD dim = x.DaysInMonth();
  369.   _tprintf(_T("This month contains %d days \n"), dim);
  370.   x.AddYear(100);
  371.   s = x.Format();
  372.   _tprintf(_T("100 years from today is %s\n"), s);
  373.   x.AddYear(-100);
  374.   s = x.Format();
  375.   _tprintf(_T("100 years from today - 100 years is %s\n"), s);
  376.   x.AddMonth(100);
  377.   s = x.Format();
  378.   _tprintf(_T("100 months from today is %s\n"), s);
  379.   x.AddMonth(-100);
  380.   s = x.Format();
  381.   _tprintf(_T("100 months from today - 100 months is %s\n"), s);
  382.   x.AddWeek(100);
  383.   s = x.Format();
  384.   _tprintf(_T("100 weeks from today is %s\n"), s);
  385.   x.AddWeek(-100);
  386.   s = x.Format();
  387.   _tprintf(_T("100 weeks from today - 100 weeks is %s\n"), s);
  388.   dow = x.GetDayOfWeek();
  389.   _tprintf(_T("Todays day of week is %d\n"), dow);
  390.   s = x.GetFullStringDayOfWeek();
  391.   _tprintf(_T("Todays full string day of week is %s\n"), s);
  392.   s = x.GetAbrStringDayOfWeek();
  393.   _tprintf(_T("Todays Abreviated string day of week is %s\n"), s);
  394.   s = x.GetFullStringMonth();
  395.   _tprintf(_T("Todays full string Month is %s\n"), s);
  396.   s = x.GetAbrStringMonth();
  397.   _tprintf(_T("Todays Abreviated string Month is %s\n"), s);
  398.   _tprintf(_T("Today is %d days since the 1st of this year\n"), x.DaysSinceJan1());
  399.   _tprintf(_T("Today is %d days since the 0th of this year\n"), x.DaysSinceJan0());
  400.   
  401.   if (x.InGregorianCalendar())
  402.     _tprintf(_T("Today is in the Gregorian Calendar\n"));
  403.   else
  404.     _tprintf(_T("Today is in the Julian Calendar\n"));
  405.  
  406.  
  407.   //Creation of other CDate's from this instance
  408.   x = CDate(1995, 2, 3);
  409.   s = x.Format();
  410.   _tprintf(_T("The CDate used to test CDate creation from this instance is %s\n"), s);
  411.   CDate c = x.FirstThisMonth();
  412.   s = c.Format();
  413.   _tprintf(_T("FirstThisMonth returns %s\n"), s);
  414.   c = x.LastThisMonth();
  415.   s = c.Format();
  416.   _tprintf(_T("LastThisMonth returns %s\n"), s);
  417.   c = x.FirstThisYear();
  418.   s = c.Format();
  419.   _tprintf(_T("FirstThisYear returns %s\n"), s);
  420.   c = x.LastThisYear();
  421.   s = c.Format();
  422.   _tprintf(_T("LastThisYear returns %s\n"), s);
  423.  
  424.  
  425.   //assigment operator has been tested before
  426.   x = CDate::CurrentDate();
  427.   c = x + 100;
  428.   s = c.Format();
  429.   _tprintf(_T("100 days from today is %s\n"), s);
  430.   c = c - 100;
  431.   s = c.Format();
  432.   _tprintf(_T("100 days from today  - 100 days is %s\n"), s);
  433.   long diff = CDate(2000, 1, 1) - CDate::CurrentDate();
  434.   _tprintf(_T("the timespan between Epoch 2000 and today is %ld\n"), diff);
  435.   c += 1000;
  436.   s = c.Format();
  437.   _tprintf(_T("today incremented by 1000 days is %s\n"), s);
  438.   c -= 1000;
  439.   s = c.Format();
  440.   _tprintf(_T("today incremented by 1000 days decremented by 1000 is %s\n"), s);
  441.   ++c;
  442.   s = c.Format();
  443.   _tprintf(_T("Tomorrow is %s\n"), s);
  444.   --c;
  445.   --c;
  446.   s = c.Format();
  447.   _tprintf(_T("Yesterday was %s\n"), s);
  448.  
  449.  
  450.   //try out the Dump operator
  451. #ifdef _DEBUG
  452.   afxDump << c;
  453. #endif
  454.   c.Set();
  455. #ifdef _DEBUG
  456.   afxDump << c;
  457. #endif
  458.  
  459.  
  460.   c = CDate::CurrentDate();
  461.   
  462.   //Full test of the Format function
  463.   _tprintf(_T("A full test of Format for Today gives\n"));
  464.   s = c.Format(_T("%a"));
  465.   _tprintf(_T("Abbreviated weekday name : %s\n"), s);
  466.   s = c.Format(_T("%A"));
  467.   _tprintf(_T("Full weekday name : %s\n"), s);
  468.   s = c.Format(_T("%b"));
  469.   _tprintf(_T("Abbreviated month name : %s\n"), s);
  470.   s = c.Format(_T("%c"));
  471.   _tprintf(_T("Year displayed using CE / BCE convention : %s\n"), s);
  472.   s = c.Format(_T("%B"));
  473.   _tprintf(_T("Full month name : %s\n"), s);
  474.   s = c.Format(_T("%d"));
  475.   _tprintf(_T("Day of month as decimal number (01 - 31) : %s\n"), s);
  476.   s = c.Format(_T("%j"));
  477.   _tprintf(_T("Day of year as decimal number (001 - 366) : %s\n"), s);
  478.   s = c.Format(_T("%m"));
  479.   _tprintf(_T("Month as decimal number (01 - 12) : %s\n"), s);
  480.   s = c.Format(_T("%U"));
  481.   _tprintf(_T("Week of year as decimal number : %s\n"), s);
  482.   s = c.Format(_T("%w"));
  483.   _tprintf(_T("Weekday as decimal number (1 - 7), Sunday is 1 : %s\n"), s);
  484.   s = c.Format(_T("%x"));
  485.   _tprintf(_T("Date representation for current locale : %s\n"), s);
  486.   s = c.Format(_T("%y"));
  487.   _tprintf(_T("Year without century, as decimal number (00 - 99) : %s\n"), s);
  488.   s = c.Format(_T("%Y"));
  489.   _tprintf(_T("Year with century, as decimal number : %s\n"), s);
  490.   s = c.Format(_T("%#x"));
  491.   _tprintf(_T("Long date representation, appropriate to current locale : %s\n"), s);
  492.   s = c.Format(_T("%#d"));
  493.   _tprintf(_T("Day of month without leading zeros : %s\n"), s);
  494.   s = c.Format(_T("%#j"));
  495.   _tprintf(_T("Day of year without leading zeros : %s\n"), s);
  496.   s = c.Format(_T("%#m"));
  497.   _tprintf(_T("Month without leading zeroes : %s\n"), s);
  498.   s = c.Format(_T("%#U"));
  499.   _tprintf(_T("Week of year without leading zeroes : %s\n"), s);
  500.   s = c.Format(_T("%#y"));
  501.   _tprintf(_T("Year without century without leading zeroes : %s\n"), s);
  502.   
  503.  
  504.  
  505.   /*
  506.   virtual void Serialize(CArchive& ar);
  507.   friend ostream& operator<<(ostream& os, const CDate& Date);
  508.   friend CArchive& operator<<(CArchive& ar, CDate& Date);
  509.   friend CArchive& operator>>(CArchive& ar, CDate& Date);
  510.   */
  511.  
  512.  
  513.  
  514.   // Try out the week of year function
  515.   x = CDate(1997, 1, 1);
  516.   s = x.Format();
  517.   _tprintf(_T("The first of January for testing the Week Of Year function is %s\n"), s);
  518.   //_tprintf(_T("Setting the begining of the week to THURSDAY\n"));
  519.   CDate v = CDate(1997, CDate::JANUARY, 1, CDate::THURSDAY);
  520.   s = v.Format();
  521.   _tprintf(_T("The 1st Thursday of 1997 is %s\n"), s);
  522.   //CDate::SetBeginingDayOfWeek(CDate::THURSDAY);
  523.   for (WORD i=1; i<32; i++)
  524.   {
  525.     CDate p(1997, 1, i);
  526.     WORD woy = p.GetWeekOfYear();
  527.     s = p.Format();
  528.     _tprintf(_T("The week of the year for %s is"), s);
  529.     _tprintf(_T(" %d\n"), woy);
  530.   }
  531.  
  532.  
  533.   // Try out the week of year function
  534.   x = CDate(1997, 1, 1);
  535.   s = x.Format();
  536.   _tprintf(_T("The first of january for testing the Week Of year function is %s\n"), s);
  537.   v = CDate(1997, CDate::JANUARY, 1, CDate::MONDAY);
  538.   s = v.Format();
  539.   _tprintf(_T("The 1st Monday of 1997 is %s\n"), s);
  540.   //_tprintf(_T("Setting the begining of the week to MONDAY\n"));
  541.   //CDate::SetBeginingDayOfWeek(CDate::MONDAY);
  542.   for (i=1; i<32; i++)
  543.   {
  544.     CDate p(x.GetYear(), x.GetMonth(), i);
  545.     WORD woy = p.GetWeekOfYear();
  546.     s = p.Format();
  547.     _tprintf(_T("The week of the year for %s is"), s);
  548.     _tprintf(_T(" %d\n"), woy);
  549.   }
  550.  
  551.  
  552.   // Try out the week of month function
  553.   x = CDate::CurrentDate();
  554.   x = x.FirstThisMonth();
  555.   s = x.Format();
  556.   _tprintf(_T("The first of this month for testing the Week Of month function is %s\n"), s);
  557.   v = CDate(x.GetYear(), x.GetMonth(), 1, CDate::THURSDAY);
  558.   s = v.Format();
  559.   _tprintf(_T("The 1st Thursday of the month is %s\n"), s);
  560.   _tprintf(_T("Setting the begining of the week to THURSDAY\n"));
  561.   //CDate::SetBeginingDayOfWeek(CDate::THURSDAY);
  562.   for (i=1; i<=x.DaysInMonth(); i++)
  563.   {
  564.     CDate p(x.GetYear(), x.GetMonth(), i);
  565.     WORD wom = p.GetWeekOfMonth();
  566.     s = p.Format();
  567.     _tprintf(_T("The week of the month for %s is"), s);
  568.     _tprintf(_T(" %d\n"), wom);
  569.   }
  570.  
  571.  
  572.  
  573.   // Try out the week of Month function with a different begining of week
  574.   x = CDate::CurrentDate();
  575.   x = x.FirstThisMonth();
  576.   s = x.Format();
  577.   _tprintf(_T("The first of this month for testing the Week Of month function is %s\n"), s);
  578.   v = CDate(x.GetYear(), x.GetMonth(), 1, CDate::MONDAY);
  579.   s = v.Format();
  580.   _tprintf(_T("The 1st Monday of the month is %s\n"), s);
  581.   _tprintf(_T("Setting the begining of the week to MONDAY\n"));
  582.   //CDate::SetBeginingDayOfWeek(CDate::MONDAY);
  583.   for (i=1; i<=x.DaysInMonth(); i++)
  584.   {
  585.     CDate p(x.GetYear(), x.GetMonth(), i);
  586.     WORD wom = p.GetWeekOfMonth();
  587.     s = p.Format();
  588.     _tprintf(_T("The week of the month for %s is"), s);
  589.     _tprintf(_T(" %d\n"), wom);
  590.   }
  591.  
  592.  
  593.  
  594.   //try out the collate function
  595.   x = CDate::CurrentDate();
  596.   long coll = x.Collate();
  597.   _tprintf(_T("The collate function for today returns %ld\n"), coll);
  598.  
  599.  
  600.  
  601.  
  602.   //Test of the CLTimeSpan class
  603.  
  604.   
  605.   //first the constructors
  606.   CLTimeSpan ts;
  607.   ASSERT(!ts.IsValid());
  608.  
  609.   ts = CLTimeSpan(3, 4, 5, 6);
  610.   long dd = ts.GetTotalDays();
  611.   WORD hh = ts.GetHours();
  612.   WORD mm = ts.GetMinutes();
  613.   WORD ss = ts.GetSeconds();
  614.   s = ts.Format();
  615.  
  616.   ts = CLTimeSpan(3, 27, 59, 69);
  617.   s = ts.Format();
  618.  
  619.   ts = CLTimeSpan(-3, 4, 5, 6);
  620.   s = ts.Format();
  621.  
  622.   CLTimeSpan ts2(ts);
  623.   s = ts2.Format();
  624.  
  625.   CTimeSpan OneDay(1, 0, 0, 0);
  626.   ts = CLTimeSpan(OneDay);
  627.   s = ts.Format();
  628.  
  629.   ts = CLTimeSpan(86400.5);
  630.   s = ts.Format();
  631.  
  632.   ts = CLTimeSpan(-23.5);
  633.   dd = ts.GetTotalDays();
  634.   hh = ts.GetHours();
  635.   mm = ts.GetMinutes();
  636.   ss = ts.GetSeconds();
  637.   s = ts.Format();
  638.   double secs = ts.SecondsAsDouble();
  639.  
  640.   ts = CLTimeSpan(-86401.5987);
  641.   dd = ts.GetTotalDays();
  642.   hh = ts.GetHours();
  643.   mm = ts.GetMinutes();
  644.   ss = ts.GetSeconds();
  645.   s = ts.Format();
  646.   secs = ts.SecondsAsDouble();
  647.  
  648.   ts = CLTimeSpan(-86401.5981);
  649.   dd = ts.GetTotalDays();
  650.   hh = ts.GetHours();
  651.   mm = ts.GetMinutes();
  652.   ss = ts.GetSeconds();
  653.   s = ts.Format();
  654.   secs = ts.SecondsAsDouble();
  655.   
  656.   ts = CLTimeSpan(86399.999);
  657.   s = ts.Format();
  658.   secs = ts.SecondsAsDouble();
  659.  
  660.   //COleDateTimeSpan Construction
  661.   COleDateTimeSpan olets(19, 12, 10, 3);
  662.   ts = CLTimeSpan(olets);  
  663.   s = ts.Format();
  664.  
  665.   //The __int64 constructor
  666.   ts = CLTimeSpan(3155760000);
  667.   dd = ts.GetTotalDays();
  668.   hh = ts.GetHours();
  669.   mm = ts.GetMinutes();
  670.   ss = ts.GetSeconds();
  671.   s = ts.Format();
  672.  
  673.  
  674.  
  675.   //Set operators have been tested via the constructors
  676.  
  677.   //static Constructors
  678.  
  679.   ts = CLTimeSpan::OneCivilYear();
  680.   s = ts.Format();
  681.   _tprintf(_T("One Civil year as a time span is %s\n"), s);
  682.   ts = CLTimeSpan::OneDay();
  683.   s = ts.Format();
  684.   _tprintf(_T("One Day as a time span is %s\n"), s);
  685.   ts = CLTimeSpan::OneHour();
  686.   s = ts.Format();
  687.   _tprintf(_T("One Hour as a time span is %s\n"), s);
  688.   ts = CLTimeSpan::OneMinute();
  689.   s = ts.Format();
  690.   _tprintf(_T("One Minute as a time span is %s\n"), s);
  691.   ts = CLTimeSpan::OneSecond();
  692.   s = ts.Format();
  693.   _tprintf(_T("One Second as a time span is %s\n"), s);
  694.  
  695.   //days, Hours, Minutes & seconds accessors
  696.   //already tested via Format
  697.   
  698.  
  699.   //Overloaded Arithmetic Operators
  700.   CLTimeSpan ts1 = CLTimeSpan::OneCivilYear();
  701.   ts2 = CLTimeSpan::OneDay();
  702.   //operator= already tested           //not fully tested yet
  703.   CLTimeSpan ts3 = ts1 + ts2;
  704.   _tprintf(_T("One year + One day is %s\n"), ts3.Format());
  705.   ts3 = ts1 - ts2;
  706.   _tprintf(_T("One year - One day is %s\n"), ts3.Format());
  707.   ts3 = ts2 - ts1;
  708.  
  709.   _tprintf(_T("One day - One year is %s\n"), ts3.Format());
  710.   ts1 = CLTimeSpan::OneCivilYear();
  711.   ts2 = CLTimeSpan::OneDay();
  712.   ts1 += ts2;
  713.   _tprintf(_T("One year incremented by one day is %s\n"), ts1.Format());
  714.   ts1 -= ts2;
  715.   _tprintf(_T("One year+one day decremented by one day is %s\n"), ts1.Format());
  716.   ts1 = CLTimeSpan::OneCivilYear();
  717.   ts2 -= ts1;
  718.   _tprintf(_T("One day decremented by one year is %s\n"), ts2.Format());
  719.   ts1 = CLTimeSpan::OneCivilYear();
  720.   ts1.Negate();
  721.   ts2 = CLTimeSpan::OneDay();
  722.   ts3 = ts1 - ts2;
  723.   _tprintf(_T("-One year - one day is %s\n"), ts3.Format());
  724.   ts3 = ts1 + ts2;
  725.   _tprintf(_T("-One year + one day is %s\n"), ts3.Format());
  726.   ts1 = CLTimeSpan::OneCivilYear();
  727.   ts2 = CLTimeSpan::OneDay();
  728.   ts2.Negate();
  729.   ts3 = ts1 - ts2;
  730.   _tprintf(_T("One year - (-one day) is %s\n"), ts3.Format());
  731.   ts3 = ts1 + ts2;
  732.   _tprintf(_T("One year + (-one day) is %s\n"), ts3.Format());
  733.   ts1 = CLTimeSpan::OneCivilYear();
  734.   ts1.Negate();
  735.   ts2 = CLTimeSpan::OneDay();
  736.   ts1 += ts2;
  737.   _tprintf(_T("-One year incremented by one day is %s\n"), ts1.Format());
  738.   ts1 -= ts2;
  739.   _tprintf(_T("-One year + 1 day decremented by one day is %s\n"), ts1.Format());
  740.   ts2 = CLTimeSpan::OneCivilYear();
  741.   ts2.Negate();
  742.   ts1 -= ts2;
  743.   _tprintf(_T("-One year decremented by -one year is %s\n"), ts1.Format());
  744.   ts1 += ts2;
  745.   _tprintf(_T("-One year - -one year incremented by -one year is %s\n"), ts1.Format());
  746.   ts1 = CLTimeSpan::OneCivilYear();
  747.   ts2 = CLTimeSpan::OneDay();
  748.   ts2.Negate();
  749.   ts3 = ts1 - ts2;
  750.   _tprintf(_T("One year - -one day is %s\n"), ts3.Format());
  751.   ts3 = ts1 + ts2;
  752.   _tprintf(_T("One year + -one day is %s\n"), ts3.Format());
  753.   ts3 = ts2 - ts1;
  754.   _tprintf(_T("-One day - one year is %s\n"), ts3.Format());
  755.   ts3 = ts2 + ts1;
  756.   _tprintf(_T("-One day + one year is %s\n"), ts3.Format());
  757.   ts1 = CLTimeSpan::OneCivilYear();
  758.   ts2 = CLTimeSpan::OneDay();
  759.   ts3 = ts1 * 100;
  760.   
  761.   dd = ts3.GetTotalDays();
  762.   hh = ts3.GetHours();
  763.   mm = ts3.GetMinutes();
  764.   ss = ts3.GetSeconds();
  765.   s = ts3.Format();
  766.   
  767.   _tprintf(_T("One year * 100 is %s\n"), ts3.Format());
  768.   ts3 = 100 * ts1;
  769.   _tprintf(_T("100 * One year is %s\n"), ts3.Format());
  770.   ts3 = ts1 / 3;
  771.   _tprintf(_T("One year / 3 is %s\n"), ts3.Format());
  772.   ts1 *= 100;
  773.   _tprintf(_T("One year *= 100 is %s\n"), ts1.Format());
  774.   ts1 = CLTimeSpan::OneCivilYear();
  775.   ts1 /= 100;
  776.   _tprintf(_T("One year /= 100 is %s\n"), ts1.Format());
  777.   ts1 = CLTimeSpan(365, 6, 10, 34);
  778.   ts3 = ts1 * 100;
  779.   _tprintf(_T("%s * 100 is"), ts1.Format());
  780.   _tprintf(_T(" %s\n"), ts3.Format());
  781.   ts3 = ts1 / 100;
  782.   _tprintf(_T("%s / 100 is"), ts1.Format());
  783.   _tprintf(_T(" %s\n"), ts3.Format());
  784.  
  785.  
  786.  
  787.   //overloaded equality operators
  788.   ts1 = CLTimeSpan::OneCivilYear();
  789.   ts2 = CLTimeSpan::OneDay();
  790.   ASSERT(ts1 >= ts2);
  791.   ASSERT(ts1 > ts2);
  792.   ASSERT(ts2 < ts1);
  793.   ASSERT(ts2 <= ts1);
  794.   ASSERT(ts2 != ts1);
  795.   ASSERT(!(ts2 == ts1));
  796.   
  797.   //AssertValid() has already been tested
  798. #ifdef _DEBUG
  799.   afxDump << ts2;
  800. #endif
  801.   ts2.Set();
  802. #ifdef _DEBUG
  803.   afxDump << ts2;
  804. #endif
  805.  
  806.   
  807.   //Format has already been tested
  808.  
  809.  
  810.  
  811.  
  812.   //Try out of the CLTimeOfDay class
  813.  
  814.   //first the constructors
  815.   CLTimeOfDay tod;
  816.   ASSERT(!tod.IsValid());
  817.  
  818.   //tod = CLTimeOfDay(23, 59, 61, 0); //should assert
  819.   //tod = CLTimeOfDay(24, 59, 61, 0); //should assert
  820.   //tod = CLTimeOfDay(23, 59, 59, 1000); //should assert
  821.                      
  822.   SYSTEMTIME stnow;                   
  823.   GetLocalTime(&stnow);
  824.   tod = CLTimeOfDay(stnow);
  825.   s = tod.Format();
  826.  
  827.   CLTimeOfDay tod2(tod);
  828.   s = tod.Format();
  829.  
  830.   //tod2 = CLTimeOfDay(-23.5); //should assert
  831.   s = tod2.Format();
  832.  
  833.   //tod2 = CLTimeOfDay(-86401.5); //should assert
  834.   s = tod2.Format();
  835.  
  836.   //tod2 = CLTimeOfDay(86399.999);
  837.   //s = tod2.Format();
  838.  
  839.   //tod2 = CLTimeOfDay(86199.9766);
  840.   //s = tod2.Format();
  841.  
  842.   
  843.   //Set functions tested via the constructors
  844.  
  845.  
  846.   //The static constructors
  847.  
  848.   tod = CLTimeOfDay::CurrentTimeOfDay(LOCAL);
  849.   s = tod.Format();
  850.   _tprintf(_T("The local time of day is %s\n"), s);
  851.  
  852.   tod = CLTimeOfDay::CurrentTimeOfDay(UCT);
  853.   s = tod.Format();
  854.   _tprintf(_T("The UCT time of day is %s\n"), s);
  855.  
  856.   //tod = CLTimeOfDay::CurrentTimeOfDay(ET); //should assert
  857.   
  858.   tod = CLTimeOfDay::Midnight();
  859.   s = tod.Format();
  860.   _tprintf(_T("Midnight as a time of day is %s\n"), s);
  861.  
  862.   tod = CLTimeOfDay::Midday();
  863.   s = tod.Format();
  864.   _tprintf(_T("Midday as a time of day is %s\n"), s);
  865.  
  866.   
  867.  
  868.   //try out the operations
  869.   tod = CLTimeOfDay::CurrentTimeOfDay(UCT);
  870.   WORD wVal = tod.GetHour();
  871.   wVal = tod.GetMinute();
  872.   long lVal = tod.GetTotalSeconds();
  873.   wVal = tod.GetSecond();
  874.   ASSERT(tod.IsValid());
  875.   DWORD col = tod.Collate();
  876.   _tprintf(_T("The collate function for the Current UCT time of day is\n"));
  877.   _tprintf(_T("%ld\n"), col);
  878.   stnow = tod.GetSYSTEMTIME();
  879.  
  880.   //Arithmetic operators
  881.   
  882.   CLTimeOfDay tod3(12, 1, 2);
  883.   CLTimeSpan  ts4(1, 25, 59, 45);
  884.   //operator= already tested
  885.   CLTimeOfDay tod4 = tod3 + ts4;
  886.   s = tod4.Format();
  887.   CString s2 = tod3.Format();
  888.   CString s3 = ts4.Format();
  889.   _tprintf(_T("%s"), s2);
  890.   _tprintf(_T(" + %s = "), s3);
  891.   _tprintf(_T("%s\n"), s);
  892.  
  893.   tod2 = tod3 - ts4;
  894.   s2 = tod3.Format();
  895.   _tprintf(_T("%s"), s2);
  896.   s3 = ts4.Format();
  897.   _tprintf(_T(" - %s = "), s3);
  898.   s = tod2.Format();
  899.   _tprintf(_T("%s\n"), s);
  900.  
  901.   s2 = tod3.Format();
  902.   _tprintf(_T("%s"), s2);
  903.   tod3 += ts4;
  904.   s3 = ts4.Format();
  905.   _tprintf(_T(" += %s = "), s3);
  906.   s = tod3.Format();
  907.   _tprintf(_T("%s\n"), s);
  908.   
  909.   s2 = tod3.Format();
  910.   _tprintf(_T("%s"), s2);
  911.   tod3 -= ts4;
  912.   s3 = ts4.Format();
  913.   _tprintf(_T(" -= %s = "), s3);
  914.   s = tod3.Format();
  915.   _tprintf(_T("%s\n"), s);
  916.  
  917.   //try out negative timespans
  918.   ts4.Negate();
  919.   tod4 = tod3 + ts4;
  920.   s2 = tod3.Format();
  921.   _tprintf(_T("%s"), s2);
  922.   s3 = ts4.Format();
  923.   _tprintf(_T(" + %s = "), s3);
  924.   s = tod4.Format();
  925.   _tprintf(_T("%s\n"), s);
  926.  
  927.   tod2 = tod3 - ts4;
  928.   s2 = tod3.Format();
  929.   _tprintf(_T("%s"), s2);
  930.   s3 = ts4.Format();
  931.   _tprintf(_T(" - %s = "), s3);
  932.   s = tod2.Format();
  933.   _tprintf(_T("%s\n"), s);
  934.  
  935.   s2 = tod3.Format();
  936.   _tprintf(_T("%s"), s2);
  937.   tod3 += ts4;
  938.   s3 = ts4.Format();
  939.   _tprintf(_T(" += %s = "), s3);
  940.   s = tod3.Format();
  941.   _tprintf(_T("%s\n"), s);
  942.   
  943.   s2 = tod3.Format();
  944.   _tprintf(_T("%s"), s2);
  945.   tod3 -= ts4;
  946.   s3 = ts4.Format();
  947.   _tprintf(_T(" -= %s = "), s3);
  948.   s = tod3.Format();
  949.   _tprintf(_T("%s\n"), s);
  950.   
  951.  
  952.  
  953.   //equality operators
  954.  
  955.   CLTimeOfDay tod1(12, 1, 2);
  956.   tod2 = CLTimeOfDay(13, 0, 2);
  957.  
  958.   ASSERT(tod1 <= tod2);
  959.   ASSERT(tod1 < tod2);
  960.   ASSERT(tod2 > tod1);
  961.   ASSERT(tod2 >= tod1);
  962.   ASSERT(tod2 != tod1);
  963.   ASSERT(!(tod2 == tod1));
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.   //Try out the CLDate class
  971.  
  972.   //first the constructors
  973.   CLDate xlneg(3, CDate::JANUARY, 1, 1, 1, 0, UCT);
  974.   CDate ld = xlneg.GetCDate();
  975.   CLTimeOfDay ltod = xlneg.GetCLTimeOfDay();
  976.   CString sneg = xlneg.Format();
  977.   xlneg = CLDate(3, CDate::JANUARY, 1, 0, 0, 0, UCT);
  978.   sneg = xlneg.Format();
  979.   xlneg = CLDate(3, CDate::JANUARY, 1, 4, 3, 2, UCT);
  980.   sneg = xlneg.Format();
  981.   xlneg = CLDate(3, CDate::JANUARY, 1, 23, 59, 59, UCT);
  982.   sneg = xlneg.Format();
  983.  
  984.  
  985.   CLDate ldate;
  986.   ASSERT(!ldate.IsValid());
  987.   ldate = CLDate(1995, 10, 3, 12, 11, 10, LOCAL);
  988.   s = ldate.Format();
  989.   //SYSTEMTIME st; 
  990.   ::GetLocalTime(&st);
  991.   ldate = CLDate(st, LOCAL);
  992.   s = ldate.Format();
  993.   ldate = CLDate(1995, 3, 5, CDate::SUNDAY, 0, 0, 0, UCT); 
  994.   s = ldate.Format();
  995.   ldate = CLDate(1000, CDate::EPOCH_JD, 0, 0, 0, UCT);
  996.   s = ldate.Format();
  997.   //Copy constructor already tested
  998.  
  999.   CTime ct = CTime::GetCurrentTime();
  1000.   ldate = CLDate(ct);
  1001.   s = ldate.Format();
  1002.   ldate = CLDate(CDate::CurrentDate(), CLTimeOfDay::CurrentTimeOfDay(LOCAL), LOCAL);
  1003.   s = ldate.Format();
  1004.       
  1005.   COleDateTime ldt(1992, CDate::OCTOBER, 10, 3, 4, 5);
  1006.   ldate = CLDate(ldt, UCT);
  1007.   s = ldate.Format();
  1008.   ldt = COleDateTime(1970, 2, 1, 5, 6, 7);
  1009.   ldate = CLDate(ldt, LOCAL);
  1010.   s = ldate.Format();
  1011.   
  1012.   //Set operators tested via the constructors above
  1013.  
  1014.   //Static Constructors
  1015.   ldate = CLDate::CurrentTime(UCT);
  1016.   s = ldate.Format();   
  1017.  
  1018.   //need to test SetDefaultFormat()
  1019.  
  1020.   //check out the deltaT function
  1021.   CLTimeSpan DT = CLDate::DeltaT(ldate);
  1022.   s = DT.Format();
  1023.   
  1024.   DT = CLDate::DeltaT(CLDate(1650, 1, 1, 0, 0, 0, 0, UCT));
  1025.   s = DT.Format();
  1026.   _tprintf(_T("The DeltaT timespan for the Year 1650 is %s\n"), s);  //should be +48 Seconds
  1027.  
  1028.   DT = CLDate::DeltaT(CLDate(1750, 1, 1, 0, 0, 0, 0, UCT));
  1029.   s = DT.Format();
  1030.   _tprintf(_T("The DeltaT timespan for the Year 1750 is %s\n"), s);  //should be +13 Seconds
  1031.  
  1032.   DT = CLDate::DeltaT(CLDate(1850, 1, 1, 0, 0, 0, 0, UCT));
  1033.   s = DT.Format();
  1034.   _tprintf(_T("The DeltaT timespan for the Year 1850 is %s\n"), s);  //should be +7.1 Seconds
  1035.  
  1036.   DT = CLDate::DeltaT(CLDate(1910, 1, 1, 0, 0, 0, 0, UCT));
  1037.   s = DT.Format();
  1038.   _tprintf(_T("The DeltaT timespan for the Year 1910 is %s\n"), s);  //should be +10.5 Seconds
  1039.   
  1040.   DT = CLDate::DeltaT(CLDate(1950, 1, 1, 0, 0, 0, 0, UCT));
  1041.   s = DT.Format();
  1042.   _tprintf(_T("The DeltaT timespan for the Year 1950 is %s\n"), s);  //should be +29.1 Seconds
  1043.  
  1044.   DT = ldate.DeltaT();
  1045.   s = DT.Format();
  1046.   _tprintf(_T("The current DeltaT timespan is %s\n"), s);            //??? depends on current date
  1047.   
  1048.   DT = CLDate::DeltaT(CLDate(2000, 1, 1, 0, 0, 0, 0, UCT));
  1049.   s = DT.Format();
  1050.   _tprintf(_T("The DeltaT timespan for the Year 2000 is %s\n"), s);  //should be around +1 minute
  1051.  
  1052.  
  1053.  
  1054.   //check page 72 of the Book "Astronomical Algorithms" for 
  1055.   //other sample values of DeltaT
  1056.  
  1057.   //Need to try out the following functions
  1058.   //GetCDate & GetCLTimeOfDay tested through the Format function
  1059.   st = ldate.GetSYSTEMTIME();
  1060.   
  1061.   ldate.AddYear(10);
  1062.   s = ldate.Format();
  1063.   _tprintf(_T("10 years from now UCT is %s\n"), s);
  1064.  
  1065.   ldate = CLDate::CurrentTime(UCT);
  1066.   ldate.AddWeek(-10);
  1067.   s = ldate.Format();
  1068.   _tprintf(_T("10 weeks before today UCT is %s\n"), s);
  1069.  
  1070.   ldate = CLDate::CurrentTime(UCT);
  1071.   ldate.AddMonth(-14);
  1072.   s = ldate.Format();
  1073.   _tprintf(_T("14 months before today UCT is %s\n"), s);
  1074.  
  1075.   
  1076.   ASSERT(ldate.IsValid());     
  1077.   ldate = CLDate();
  1078.   ASSERT(!ldate.IsValid());
  1079.  
  1080.  
  1081.   //Test a daylight savings date
  1082.  
  1083.   ldate = CLDate(1995, 7, 9, 8, 7, 6, UCT);
  1084.   CString s1 = ldate.Format();
  1085.   _tprintf(_T("%s is "), s1);
  1086.   ldate.SetTimeFrame(UCT);
  1087.   s = ldate.Format();
  1088.   _tprintf(_T("%s\n"), s);
  1089.  
  1090.   ldate = CLDate(1995, 7, 9, 8, 7, 6, UCT);
  1091.   s1 = ldate.Format();
  1092.   _tprintf(_T("%s is "), s1);
  1093.   ldate.SetTimeFrame(ET);
  1094.   s = ldate.Format();
  1095.   _tprintf(_T("%s\n"), s);
  1096.  
  1097.   ldate = CLDate(1995, 7, 9, 8, 7, 6, UCT);
  1098.   s1 = ldate.Format();
  1099.   _tprintf(_T("%s is "), s1);
  1100.   ldate.SetTimeFrame(LOCAL);
  1101.   s = ldate.Format();
  1102.   _tprintf(_T("%s\n"), s);
  1103.  
  1104.   ldate = CLDate(1995, 7, 9, 8, 7, 6, ET);
  1105.   s1 = ldate.Format();
  1106.   _tprintf(_T("%s is "), s1);
  1107.   ldate.SetTimeFrame(UCT);
  1108.   s = ldate.Format();
  1109.   _tprintf(_T("%s\n"), s);
  1110.  
  1111.   ldate = CLDate(1995, 7, 9, 8, 7, 6, ET);
  1112.   s1 = ldate.Format();
  1113.   _tprintf(_T("%s is "), s1);
  1114.   ldate.SetTimeFrame(ET);
  1115.   s = ldate.Format();
  1116.   _tprintf(_T("%s\n"), s);
  1117.   
  1118.   ldate = CLDate(1995, 7, 9, 8, 7, 6, ET);
  1119.   s1 = ldate.Format();
  1120.   _tprintf(_T("%s is "), s1);
  1121.   ldate.SetTimeFrame(LOCAL);
  1122.   s = ldate.Format();
  1123.   _tprintf(_T("%s\n"), s);
  1124.  
  1125.   ldate = CLDate(1995, 7, 9, 8, 7, 6, LOCAL);
  1126.   s1 = ldate.Format();
  1127.   _tprintf(_T("%s is "), s1);
  1128.   ldate.SetTimeFrame(UCT);
  1129.   s = ldate.Format();
  1130.   _tprintf(_T("%s\n"), s);
  1131.   
  1132.   ldate = CLDate(1995, 7, 9, 8, 7, 6, LOCAL);
  1133.   s1 = ldate.Format();
  1134.   _tprintf(_T("%s is "), s1);
  1135.   ldate.SetTimeFrame(ET);
  1136.   s = ldate.Format();
  1137.   _tprintf(_T("%s\n"), s);
  1138.   
  1139.   ldate = CLDate(1995, 7, 9, 8, 7, 6, LOCAL);
  1140.   s1 = ldate.Format();
  1141.   _tprintf(_T("%s is "), s1);
  1142.   ldate.SetTimeFrame(LOCAL);
  1143.   s = ldate.Format();
  1144.   _tprintf(_T("%s\n"), s);
  1145.  
  1146.  
  1147.   //test a Standard time
  1148.  
  1149.   ldate = CLDate(1995, 12, 9, 8, 7, 6, UCT);
  1150.   s1 = ldate.Format();
  1151.   _tprintf(_T("%s is "), s1);
  1152.   ldate.SetTimeFrame(UCT);
  1153.   s = ldate.Format();
  1154.   _tprintf(_T("%s\n"), s);
  1155.  
  1156.   ldate = CLDate(1995, 12, 9, 8, 7, 6, UCT);
  1157.   s1 = ldate.Format();
  1158.   _tprintf(_T("%s is "), s1);
  1159.   ldate.SetTimeFrame(ET);
  1160.   s = ldate.Format();
  1161.   _tprintf(_T("%s\n"), s);
  1162.  
  1163.   ldate = CLDate(1995, 12, 9, 8, 7, 6, UCT);
  1164.   s1 = ldate.Format();
  1165.   _tprintf(_T("%s is "), s1);
  1166.   ldate.SetTimeFrame(LOCAL);
  1167.   s = ldate.Format();
  1168.   _tprintf(_T("%s\n"), s);
  1169.  
  1170.   ldate = CLDate(1995, 12, 9, 8, 7, 6, ET);
  1171.   s1 = ldate.Format();
  1172.   _tprintf(_T("%s is "), s1);
  1173.   ldate.SetTimeFrame(UCT);
  1174.   s = ldate.Format();
  1175.   _tprintf(_T("%s\n"), s);
  1176.  
  1177.   ldate = CLDate(1995, 12, 9, 8, 7, 6, ET);
  1178.   s1 = ldate.Format();
  1179.   _tprintf(_T("%s is "), s1);
  1180.   ldate.SetTimeFrame(ET);
  1181.   s = ldate.Format();
  1182.   _tprintf(_T("%s\n"), s);
  1183.   
  1184.   ldate = CLDate(1995, 12, 9, 8, 7, 6, ET);
  1185.   s1 = ldate.Format();
  1186.   _tprintf(_T("%s is "), s1);
  1187.   ldate.SetTimeFrame(LOCAL);
  1188.   s = ldate.Format();
  1189.   _tprintf(_T("%s\n"), s);
  1190.  
  1191.   ldate = CLDate(1995, 12, 9, 8, 7, 6, LOCAL);
  1192.   s1 = ldate.Format();
  1193.   _tprintf(_T("%s is "), s1);
  1194.   ldate.SetTimeFrame(UCT);
  1195.   s = ldate.Format();
  1196.   _tprintf(_T("%s\n"), s);
  1197.   
  1198.   ldate = CLDate(1995, 12, 9, 8, 7, 6, LOCAL);
  1199.   s1 = ldate.Format();
  1200.   _tprintf(_T("%s is "), s1);
  1201.   ldate.SetTimeFrame(ET);
  1202.   s = ldate.Format();
  1203.   _tprintf(_T("%s\n"), s);
  1204.   
  1205.   ldate = CLDate(1995, 12, 9, 8, 7, 6, LOCAL);
  1206.   s1 = ldate.Format();
  1207.   _tprintf(_T("%s is "), s1);
  1208.   ldate.SetTimeFrame(LOCAL);
  1209.   s = ldate.Format();
  1210.   _tprintf(_T("%s\n"), s);
  1211.  
  1212.  
  1213.  
  1214.   //Need to test the two conditions where a LOCAL time occurs twice 
  1215.   //or not at all
  1216.  
  1217.  
  1218.   ldate = CLDate::CurrentTime(UCT);
  1219.   s = ldate.Format();
  1220.   _tprintf(_T("The current UCT date is %s\n"), s);
  1221.   ldate = CLDate::CurrentTime(ET);
  1222.   s = ldate.Format();
  1223.   _tprintf(_T("The current ET date is %s\n"), s);
  1224.   ldate = CLDate::CurrentTime(LOCAL);
  1225.   s = ldate.Format();
  1226.   _tprintf(_T("The current LOCAL date is %s\n"), s);
  1227.  
  1228.   BOOL bInDst = ldate.IsDST();
  1229.   if (bInDst)
  1230.     _tprintf(_T("Current date is a Daylight Time\n"));
  1231.   else
  1232.     _tprintf(_T("Current date is a Standard Time\n"));
  1233.  
  1234.   //operator= already tried out
  1235.  
  1236.   ldate = CLDate::CurrentTime(UCT);
  1237.   ts = CTimeSpan(10, 10, 10, 10);
  1238.   ldate += ts;
  1239.   s1 = ts.Format();
  1240.   _tprintf(_T("%s from today UCT is "), s1);
  1241.   s = ldate.Format();
  1242.   _tprintf(_T("%s\n"), s);
  1243.  
  1244.  
  1245.   //Arithmetic operators
  1246.   ldate = CLDate::CurrentTime(LOCAL);
  1247.   CLDate ldate3 = ldate;
  1248.   ldate3.SetTimeFrame(UCT);
  1249.   ldate3 += CLTimeSpan(0, 0, 0, 1);
  1250.   ts = ldate3 - ldate;
  1251.  
  1252.  
  1253.  
  1254.   //try out the equality operators
  1255.   ldate = CLDate::CurrentTime(UCT);
  1256.   CLDate ldate2(ldate);
  1257.   ldate2.SetTimeFrame(LOCAL);
  1258.   ASSERT(ldate == ldate2);
  1259.   ASSERT(!(ldate != ldate2));
  1260.   ldate2 += CLTimeSpan(0, 0, 0, 1);
  1261.   ASSERT(ldate2 != ldate);
  1262.   ASSERT(ldate2 >= ldate);
  1263.   ASSERT(ldate <= ldate2);
  1264.   ASSERT(ldate < ldate2);
  1265.  
  1266.   //AssertValid() already tested internally
  1267.  
  1268. #ifdef _DEBUG
  1269.   afxDump << ldate;
  1270. #endif
  1271.   
  1272.   
  1273.   //Full test of the Format function
  1274.   ldate = CLDate::CurrentTime(LOCAL);
  1275.   s = ldate.Format();
  1276.   _tprintf(_T("A full test of CLDate::Format for Now (LOCAL) gives\n"));
  1277.   s = ldate.Format(_T("%a"));
  1278.   _tprintf(_T("Abbreviated weekday name : %s\n"), s);
  1279.   s = ldate.Format(_T("%A"));
  1280.   _tprintf(_T("Full weekday name : %s\n"), s);
  1281.   s = ldate.Format(_T("%b"));
  1282.   _tprintf(_T("Abbreviated month name : %s\n"), s);
  1283.   s = ldate.Format(_T("%B"));
  1284.   _tprintf(_T("Full month name : %s\n"), s);
  1285.   s = ldate.Format(_T("%c"));
  1286.   _tprintf(_T("Year displayed using CE / BCE convention : %s\n"), s);
  1287.   s = ldate.Format(_T("%d"));
  1288.   _tprintf(_T("Day of month as decimal number (01 - 31) : %s\n"), s);
  1289.   s = ldate.Format(_T("%j"));
  1290.   _tprintf(_T("Day of year as decimal number (001 - 366) : %s\n"), s);
  1291.   s = ldate.Format(_T("%m"));
  1292.   _tprintf(_T("Month as decimal number (01 - 12) : %s\n"), s);
  1293.   s = ldate.Format(_T("%U"));
  1294.   _tprintf(_T("Week of year as decimal number : %s\n"), s);
  1295.   s = ldate.Format(_T("%w"));
  1296.   _tprintf(_T("Weekday as decimal number (1 - 7), Sunday is 1 : %s\n"), s);
  1297.   s = ldate.Format(_T("%x"));
  1298.   _tprintf(_T("Date representation for current locale : %s\n"), s);
  1299.   s = ldate.Format(_T("%y"));
  1300.   _tprintf(_T("Year without century, as decimal number (00 - 99) : %s\n"), s);
  1301.   s = ldate.Format(_T("%Y"));
  1302.   _tprintf(_T("Year with century, as decimal number : %s\n"), s);
  1303.   s = ldate.Format(_T("%#x"));
  1304.   _tprintf(_T("Long date representation, appropriate to current locale : %s\n"), s);
  1305.   s = ldate.Format(_T("%#d"));
  1306.   _tprintf(_T("Day of month without leading zeros : %s\n"), s);
  1307.   s = ldate.Format(_T("%#j"));
  1308.   _tprintf(_T("Day of year without leading zeros : %s\n"), s);
  1309.   s = ldate.Format(_T("%#m"));
  1310.   _tprintf(_T("Month without leading zeroes : %s\n"), s);
  1311.   s = ldate.Format(_T("%#U"));
  1312.   _tprintf(_T("Week of year without leading zeroes, with Sunday as first day of week : %s\n"), s);
  1313.   s = ldate.Format(_T("%#y"));
  1314.   _tprintf(_T("Year without century without leading zeroes : %s\n"), s);
  1315.   s = ldate.Format(_T("%H"));
  1316.   _tprintf(_T("Hours in the current day : %s\n"), s);
  1317.   s = ldate.Format(_T("%h"));
  1318.   _tprintf(_T("AM / PM Hours in the current day : %s\n"), s);
  1319.   s = ldate.Format(_T("%P"));
  1320.   _tprintf(_T("AM / PM Indicator for the current day : %s\n"), s);
  1321.   s = ldate.Format(_T("%M"));
  1322.   _tprintf(_T("Minutes in the current day : %s\n"), s);
  1323.   s = ldate.Format(_T("%S"));
  1324.   _tprintf(_T("Seconds in the current day : %s\n"), s);
  1325.   s = ldate.Format(_T("%#H"));
  1326.   _tprintf(_T("Hours in the current day without leading zeros: %s\n"), s);
  1327.   s = ldate.Format(_T("%#h"));
  1328.   _tprintf(_T("AM / PM Hours in the current day without leading zeros: %s\n"), s);
  1329.   s = ldate.Format(_T("%#M"));
  1330.   _tprintf(_T("Minutes in the current day without leading zeros : %s\n"), s);
  1331.   s = ldate.Format(_T("%#S"));
  1332.   _tprintf(_T("Seconds in the current day without leading zeros : %s\n"), s);
  1333.   ldate = CLDate::CurrentTime(UCT);
  1334.   s = ldate.Format();
  1335.   _tprintf(_T("The Current UCT long date is %s\n"), s);
  1336.  
  1337.  
  1338.   //cross the DST marker
  1339.   _tprintf(_T("\n\n"));
  1340.  
  1341.   _tprintf(_T("Some of the following code is designed to cause ASSERTIONS\n"));
  1342.   _tprintf(_T("You can safely press IGNORE. To see why these assertions occur\n"));
  1343.   _tprintf(_T("you should trace into the DTime code\n"));
  1344.   _tprintf(_T("<Hit Enter to continue>\n"));
  1345.   chr = getchar();
  1346.  
  1347.  
  1348.   //you will need to modify these values depending on when your
  1349.   //computer is set to cross the DST marker
  1350.  
  1351.   ldate = CLDate(1996, 3, 31, 0, 10, 0, LOCAL);
  1352.   for (int p=0; p<24; p++)
  1353.   {
  1354.     CLDate OldDate(ldate);
  1355.     s = ldate.Format();
  1356.     _tprintf(_T("%s is "), s);
  1357.     ldate.SetTimeFrame(UCT);
  1358.     s1 = ldate.Format();
  1359.     _tprintf(_T("%s\n"), s1);
  1360.     ldate = OldDate;
  1361.     ldate += CLTimeSpan(0, 0, 10, 0);
  1362.   }
  1363.  
  1364.   ldate = CLDate(1996, 3, 31, 1, 59, 0, LOCAL);  //does occur
  1365.   BOOL bIsDst = ldate.IsDST();
  1366.  
  1367.   ldate = CLDate(1996, 3, 31, 2, 00, 0, LOCAL);  //does occur
  1368.   bIsDst = ldate.IsDST();
  1369.  
  1370.   ldate = CLDate(1996, 3, 31, 2, 01, 0, LOCAL);  //does not occur
  1371.   //bIsDst = ldate.IsDST();    //should assert
  1372.  
  1373.   ldate = CLDate(1996, 3, 31, 2, 30, 0, LOCAL);  //does not occur
  1374.   //bIsDst = ldate.IsDST();    //should assert
  1375.  
  1376.   ldate = CLDate(1996, 3, 31, 3, 00, 0, LOCAL);  //does occur
  1377.   bIsDst = ldate.IsDST();
  1378.  
  1379.   ldate = CLDate(1996, 10, 27, 1, 59, 0, LOCAL);  //does occur
  1380.   bIsDst = ldate.IsDST();
  1381.  
  1382.   ldate = CLDate(1996, 10, 27, 3, 00, 0, LOCAL);  //occurs twice
  1383.   //bIsDst = ldate.IsDST();    //should assert
  1384.  
  1385.   ldate = CLDate(1996, 10, 27, 2, 30, 0, LOCAL);  //occurs twice
  1386.   //bIsDst = ldate.IsDST();    //should assert
  1387.  
  1388.   ldate = CLDate(1996, 10, 27, 2, 59, 0, LOCAL);  //occurs twice
  1389.   //bIsDst = ldate.IsDST();    //should assert
  1390.  
  1391.   ldate = CLDate(1996, 10, 27, 2, 00, 0, LOCAL);  //occurs twice
  1392.   //bIsDst = ldate.IsDST();  //should assert
  1393.  
  1394.   ldate = CLDate(1996, 10, 27, 3, 01, 0, LOCAL);  //does occur
  1395.   bIsDst = ldate.IsDST();
  1396.  
  1397.   ldate = CLDate(1996, 3, 31, 1, 59, 0, UCT);
  1398.   bIsDst = ldate.IsDST();
  1399.   ldate.SetTimeFrame(LOCAL);
  1400.   s = ldate.Format();
  1401.  
  1402.   ldate = CLDate(1996, 3, 31, 2, 00, 0, UCT);
  1403.   bIsDst = ldate.IsDST();
  1404.   ldate.SetTimeFrame(LOCAL);
  1405.   s = ldate.Format();
  1406.  
  1407.   ldate = CLDate(1996, 3, 31, 2, 01, 0, UCT);
  1408.   bIsDst = ldate.IsDST();
  1409.   ldate.SetTimeFrame(LOCAL);
  1410.   s = ldate.Format();
  1411.  
  1412.   ldate = CLDate(1996, 3, 31, 2, 30, 0, UCT);
  1413.   bIsDst = ldate.IsDST();
  1414.   ldate.SetTimeFrame(LOCAL);
  1415.   s = ldate.Format();
  1416.  
  1417.   ldate = CLDate(1996, 3, 31, 2, 59, 0, UCT);
  1418.   bIsDst = ldate.IsDST();
  1419.   ldate.SetTimeFrame(LOCAL);
  1420.   s = ldate.Format();
  1421.   
  1422.   ldate = CLDate(1996, 3, 31, 3, 00, 0, UCT);
  1423.   bIsDst = ldate.IsDST();
  1424.   ldate.SetTimeFrame(LOCAL);
  1425.   s = ldate.Format();
  1426.  
  1427.   ldate = CLDate(1996, 10, 27, 1, 59, 0, UCT);
  1428.   s = ldate.Format();
  1429.   bIsDst = ldate.IsDST();
  1430.   ldate.SetTimeFrame(LOCAL);
  1431.   s = ldate.Format();
  1432.  
  1433.   ldate = CLDate(1996, 10, 27, 2, 00, 0, UCT);
  1434.   bIsDst = ldate.IsDST();
  1435.   ldate.SetTimeFrame(LOCAL);
  1436.   s = ldate.Format();
  1437.  
  1438.   ldate = CLDate(1996, 10, 27, 2, 30, 0, UCT);
  1439.   bIsDst = ldate.IsDST();
  1440.   ldate.SetTimeFrame(LOCAL);
  1441.   s = ldate.Format();
  1442.  
  1443.   ldate = CLDate(1996, 10, 27, 2, 59, 0, UCT);
  1444.   bIsDst = ldate.IsDST();
  1445.   ldate.SetTimeFrame(LOCAL);
  1446.   s = ldate.Format();
  1447.  
  1448.   ldate = CLDate(1996, 10, 27, 3, 00, 0, UCT);
  1449.   bIsDst = ldate.IsDST();
  1450.   ldate.SetTimeFrame(LOCAL);
  1451.   s = ldate.Format();
  1452.  
  1453.   ldate = CLDate(1996, 10, 27, 3, 01, 0, UCT);
  1454.   bIsDst = ldate.IsDST();
  1455.   ldate.SetTimeFrame(LOCAL);
  1456.   s = ldate.Format();
  1457.  
  1458.  
  1459.   DWORD TimeInterval = GetTickCount() - StartTicks;
  1460.   _tprintf(_T("Time taken to execute program in milliseconds is : %ld\n"), TimeInterval);
  1461.   
  1462.   return FALSE;
  1463. }
  1464.